package com.Cfeng.XiaohuanChat.domain;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author Cfeng
 * @date 2022/8/7
 * 该类定义响应实体，定义相关的属性
 * 也可以直接使用ResponseEntity<T>
 */

@Accessors(chain = true)
@Data
public class Resp<T> {

    private Integer code; //响应状态码

    private T data; //响应数据

    private String message; //错误提示信息

    //访问成功或者失败
    private static final Integer SUCCESS = 0;

    private static final Integer FAILED = -1;

    //访问ok成功
    public static <T> Resp<T> ok(T data) {
        return new Resp<T>().setCode(SUCCESS).setData(data);
    }

    //访问失败
    public static <T> Resp<T> failed(String message) {
        return new Resp<T>().setCode(FAILED).setMessage(message);
    }
}
